﻿//
// Created by HuiYi on 2022/12/16.
//

#ifndef REF_TEST_REFREGISTER_HPP
#define REF_TEST_REFREGISTER_HPP
#include <vector>

typedef unsigned int UINT;

inline bool WoRefFillFuncInt(void* ptr, const char* row) {
    *((int*)ptr)= atoi(row);
    return true;
}
inline bool WoRefFillFuncUint(void* ptr, const char* row) {
    *((UINT*)ptr)=static_cast<unsigned int>(atoi(row));
    return true;
}
inline bool WoRefFillFuncFloat(void* ptr, const char* row) {
    *((float*)ptr)= atof(row);
    return true;
}
inline bool WoRefFillFuncDouble(void* ptr, const char* row) {
    *((double*)ptr)= atof(row);
    return true;
}
inline bool WoRefFillFuncLong(void* ptr, const char* row) {
    *((long*)ptr)= atol(row);
    return true;
}
inline bool WoRefFillFuncLongLong(void* ptr, const char* row) {
    *((long long*)ptr)= atoll(row);
    return true;
}
inline bool WoRefFillFuncBOOL(void* ptr, const char* row) {
    bool bk = false;
    bool rbool = false;
    if (strcmp(row,"true")==0) {
        rbool = true;
    }
    else if (strcmp(row, "True") == 0) {
        rbool = true;
    }
    else if (strcmp(row, "TRUE") == 0) {
        rbool = true;
    }
    else if (strcmp(row, "真") == 0) {
        rbool = true;
    }
    else if (strcmp(row, "false") == 0) {
        rbool = false;
    }
    else if (strcmp(row, "False") == 0) {
        rbool = false;
    }
    else if (strcmp(row, "FALSE") == 0) {
        rbool = false;
    }
    else if (strcmp(row, "假") == 0) {
        rbool = false;
    }
    *((long long*)ptr) = rbool;
    return true;
}
/*inline bool WoRefFillFuncCXTextA(void* ptr, const char* row) {
    *(CXTextA*)(((WOPTR)ptr) + m->deviation) = row;
    return true;
}*/
inline bool WoRefFillFuncString(void* ptr, const char* row) {
    *((std::string*)ptr) = row;
    return true;
}

inline void refInit(){
    struct _refInitModel{
        std::string typeName;
        int size;
        RefBaseModelFunc func;
    };
    std::vector<_refInitModel> regList={
            {typeid(int).name(),sizeof(int),WoRefFillFuncInt},
            {typeid(UINT).name(),sizeof(UINT), WoRefFillFuncUint},
            {typeid(double).name(),sizeof(double), WoRefFillFuncDouble},
            {typeid(float).name(),sizeof(float), WoRefFillFuncFloat},
            {typeid(long).name(),sizeof(long), WoRefFillFuncLong},
            {typeid(long long).name(),sizeof(long long), WoRefFillFuncLongLong},
            {typeid(bool).name(),sizeof(bool), WoRefFillFuncBOOL},
            {typeid(std::string).name(),sizeof(std::string), WoRefFillFuncString},
    };
    for(auto& regInfo:regList){
        RefRegBaseModelEx(regInfo.typeName.c_str(),regInfo.size,regInfo.func);
    }

}


#endif //REF_TEST_REFREGISTER_HPP
